from typing import Generic, TypeVar, List, Optional
from pydantic import BaseModel

T = TypeVar('T')

class BasePage(BaseModel):
    """基础分页请求模型，对应前端BasePage接口"""
    page: int = 1
    page_size: int = 10

class PageResult(Generic[T], BaseModel):
    """分页结果模型"""
    items: List[T]
    total: int
    page: int
    page_size: int
    
    class Config:
        arbitrary_types_allowed = True

def paginate(items: List, page: int = 1, page_size: int = 10) -> dict:
    """对列表数据进行分页
    
    Args:
        items: 要分页的列表
        page: 当前页码
        page_size: 每页大小
        
    Returns:
        dict: 包含分页结果的字典
    """
    total = len(items)
    start = (page - 1) * page_size
    end = start + page_size
    
    return {
        "items": items[start:end],
        "total": total,
        "page": page,
        "page_size": page_size
    }
